<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item style="cursor:pointer;" :to="{path:'/TestPlanRunning',query:this.queryParams}"><span style="cursor:pointer;">返回</span></el-breadcrumb-item>
    </el-breadcrumb>
    <div class="info">
      <el-card v-loading="dataLoading">
        <el-row><div class="rectangularBar"></div><div class="heardTitle">公共参数</div></el-row>
        <el-form :model="publicParams" ref="publicParams" :rules="publicParamsRules" :inline-message="true" label-width="115px" style="margin-top: 10px">
          <el-row>
            <el-col :span="8"><el-form-item label="委试号：" prop="testNumber">
              <el-input v-model="publicParams.testNumber" size="small" placeholder="请输入委试号" clearable></el-input>
            </el-form-item></el-col>
            <el-col :span="8"><el-form-item label="试品模板："><span class="text">{{publicParams.tpltName}}</span></el-form-item></el-col>
            <el-col :span="8"><el-form-item label="试品名称："><span class="text">{{publicParams.prodName}}</span></el-form-item></el-col>
          </el-row>
          <el-row>
            <el-col :span="8"><el-form-item label="海拔参数m："><span class="text">{{publicParams.kaM}}</span></el-form-item></el-col>
            <el-col :span="8"><el-form-item label="适用海拔(m)："><span class="text">{{publicParams.seaLevel}}</span></el-form-item></el-col>
            <el-col :span="8"><el-form-item label="温度(℃)："><span class="text">{{publicParams.temperature}}</span></el-form-item></el-col>
          </el-row>
          <el-row>
            <el-col :span="8"><el-form-item label="相对湿度(%RH)："><span class="text">{{publicParams.humidity}}</span></el-form-item></el-col>
            <el-col :span="8"><el-form-item label="大气压(kpa)："><span class="text">{{publicParams.pressure}}</span></el-form-item></el-col>
          </el-row>
          <el-row>
            <el-col :span="24"><el-form-item label="试验类型："><span class="text">{{publicParams.testKind}}</span></el-form-item></el-col>
          </el-row>
          <el-row>
            <el-col :span="24"><el-form-item label="试验依据标准："><span class="text">{{publicParams.gjbName}}</span></el-form-item></el-col>
          </el-row>
        </el-form>
        <el-row><div class="rectangularBar"></div><div class="heardTitle">试验参数</div></el-row>
        <el-tabs v-model="activeName" style="margin: 10px 20px 0px 20px">
          <el-tab-pane label="雷电冲击耐受电压试验" name="first" v-if="showliEquip">
            <el-form :model="liEquipParams" ref="liEquipParams" label-width="135px" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-col :span="8"><el-form-item label="充电时间(s)："><span class="text">{{liEquipParams.chargeTime}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="首次充电电压(kVp)："><span class="text">{{liEquipParams.chargeVolt}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="老练次数："><span class="text">{{liEquipParams.bufferCnt}}</span></el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="8"><el-form-item label="计数器(次)："><span class="text">{{liEquipParams.chargeCnt}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="连续放电："><span class="text">{{liEquipParams.ifDischarge}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="C(μF)："><span class="text">{{liEquipParams.paramC}}</span></el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="8"><el-form-item label="C1(pF)："><span class="text">{{liEquipParams.paramC1}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="Rf(Ω)："><span class="text">{{liEquipParams.paramRf}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="Rt(Ω)："><span class="text">{{liEquipParams.paramRt}}</span></el-form-item></el-col>
              </el-row>
            </el-form>
            <div class="formItem"><el-form :model="liEquipForm" :rules="liEquipParamsRules" ref="liEquipForm" label-width="0px" size="small" :inline-message="true">
              <el-table :data="liEquipForm.liEquipTableData" size="small" border style="width: 100%;margin-bottom:20px" :header-cell-style="{background:'#F7F7FB'}">
                <el-table-column property="part_name" label="试验部位" show-overflow-tooltip></el-table-column>
                <el-table-column label="原始电压(kVp)">
                  <template slot-scope="props">
                    <el-form-item :prop="'liEquipTableData.' + props.$index + '.origin_volt'" :rules="[{ required: true, message: '请输入原始电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.origin_volt" size="small" placeholder="请输入原始电压" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否校大气">
                  <template slot-scope="props">
                    <el-select v-model="props.row.if_calair" size="small" v-if="props.row.if_calair !== '2'" style="width:100%">
                      <el-option label="是" value="1"></el-option>
                      <el-option label="否" value="0"></el-option>
                    </el-select>
                    <span v-if="props.row.if_calair === '2'">不允许校大气</span>
                  </template>
                </el-table-column>
                <el-table-column label="试验电压百分比(%)">
                  <template slot-scope="props">
                    <el-form-item :prop="'liEquipTableData.' + props.$index + '.percent_volt'" :rules="[{ required: true, message: '请输入试验电压百分比', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.percent_volt" size="small" placeholder="请输入试验电压百分比" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column property="remark" label="备注" show-overflow-tooltip></el-table-column>
              </el-table>
            </el-form></div>
          </el-tab-pane>
          <el-tab-pane label="工频耐受电压试验" name="second" v-if="showACEquip">
            <el-form :model="acEquipParams" ref="acEquipParams" label-width="140px" size="small" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-col :span="8"><el-form-item label="采样间隔(s)："><span class="text">{{acEquipParams.collectInterval}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="耐压时间(s)："><span class="text">{{acEquipParams.withstandTime}}</span></el-form-item></el-col>
                <!-- <el-col :span="8"><el-form-item label="高速设置(%)："><span class="text">{{acEquipParams.highSpeed}}</span></el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="8"><el-form-item label="低速设置(%)："><span class="text">{{acEquipParams.lowSpeed}}</span></el-form-item></el-col> -->
              </el-row>
            </el-form>
            <div class="formItem"><el-form :model="acEquipForm" :rules="liEquipParamsRules" ref="acEquipForm" label-width="0px" size="small" :inline-message="true">
              <el-table :data="acEquipForm.acEquipTableData" size="small" border style="width: 100%;margin-bottom:20px" :header-cell-style="{background:'#F7F7FB'}">
                <el-table-column property="part_name" label="试验部位" show-overflow-tooltip></el-table-column>
                <el-table-column label="原始电压(kVp)">
                  <template slot-scope="props">
                      <el-form-item :prop="'acEquipTableData.' + props.$index + '.origin_volt'" :rules="[{ required: true, message: '请输入原始电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                        <el-input v-model="props.row.origin_volt" size="small" placeholder="请输入原始电压" clearable></el-input>
                      </el-form-item>
                    </template>
                </el-table-column>
                <el-table-column label="是否校大气">
                  <template slot-scope="props">
                    <el-select v-model="props.row.if_calair" size="small" v-if="props.row.if_calair !== '2'" style="width:100%">
                      <el-option label="是" value="1"></el-option>
                      <el-option label="否" value="0"></el-option>
                    </el-select>
                    <span v-if="props.row.if_calair === '2'">不允许校大气</span>
                  </template>
                </el-table-column>
                <el-table-column label="试验电压百分比(%)">
                  <template slot-scope="props">
                    <el-form-item :prop="'acEquipTableData.' + props.$index + '.percent_volt'" :rules="[{ required: true, message: '请输入试验电压百分比', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.percent_volt" size="small" placeholder="请输入试验电压百分比" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column property="remark" label="备注" show-overflow-tooltip></el-table-column>
              </el-table>
            </el-form></div>
          </el-tab-pane>
          <el-tab-pane label="工频耐受电压试验(湿)" name="fourth" v-if="showACWet">
            <el-form :model="acWetEquipParams" ref="acWetEquipParams" label-width="140px" size="small" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-col :span="8"><el-form-item label="采样间隔(s)："><span class="text">{{acWetEquipParams.collectInterval}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="耐压时间(s)："><span class="text">{{acWetEquipParams.withstandTime}}</span></el-form-item></el-col>
                <!-- <el-col :span="8"><el-form-item label="高速设置(%)："><span class="text">{{acWetEquipParams.highSpeed}}</span></el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="8"><el-form-item label="低速设置(%)："><span class="text">{{acWetEquipParams.lowSpeed}}</span></el-form-item></el-col> -->
                <el-col :span="8"><el-form-item label="水温(℃)："><span class="text">{{acWetEquipParams.waterTemp}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="雨水电导率(μS/cm)："><span class="text">{{acWetEquipParams.rainElect}}</span></el-form-item></el-col>
              <!-- </el-row>
              <el-row> -->
                <el-col :span="8"><el-form-item label="水平分量(mm/min)："><span class="text">{{acWetEquipParams.horizCompont}}</span></el-form-item></el-col>
                <el-col :span="8"><el-form-item label="垂直分量(mm/min)："><span class="text">{{acWetEquipParams.verticalCompont}}</span></el-form-item></el-col>
              </el-row>
            </el-form>
            <div class="formItem"><el-form :model="acWetEquipForm" :rules="liEquipParamsRules" ref="acWetEquipForm" label-width="0px" size="small" :inline-message="true">
              <el-table :data="acWetEquipForm.wetACTableData" size="small" border style="width: 100%;margin-bottom:20px" :header-cell-style="{background:'#F7F7FB'}">
                <el-table-column property="part_name" label="试验部位" show-overflow-tooltip></el-table-column>
                <el-table-column label="原始电压(kVp)">
                  <template slot-scope="props">
                    <el-form-item :prop="'wetACTableData.' + props.$index + '.origin_volt'" :rules="[{ required: true, message: '请输入原始电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.origin_volt" size="small" placeholder="请输入原始电压" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否校大气">
                  <template slot-scope="props">
                    <el-select v-model="props.row.if_calair" size="small" v-if="props.row.if_calair !== '2'" style="width:100%">
                      <el-option label="是" value="1"></el-option>
                      <el-option label="否" value="0"></el-option>
                    </el-select>
                    <span v-if="props.row.if_calair === '2'">不允许校大气</span>
                  </template>
                </el-table-column>
                <el-table-column label="试验电压百分比(%)">
                  <template slot-scope="props">
                    <el-form-item :prop="'wetACTableData.' + props.$index + '.percent_volt'" :rules="[{ required: true, message: '请输入试验电压百分比', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.percent_volt" size="small" placeholder="请输入试验电压百分比" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column property="remark" label="备注" show-overflow-tooltip></el-table-column>
              </el-table>
            </el-form></div>
          </el-tab-pane>
          <el-tab-pane label="气候防护试验" name="third" v-if="showDefend">
            <el-form :model="defendParams" ref="defendParams" label-width="130px" size="small" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-form-item label="防护等级"><span class="text">{{defendParams.protectId}}</span></el-form-item>
              </el-row>
              <el-row>显示试品尺寸(仅支持防护等级为IPX3 IPX4 IPX5 IPX5W IPX6)</el-row>
              <el-table v-if="defendParams.defendTableData.length !== 0" :data="defendParams.defendTableData" border style="width: 100%" :header-cell-style="{background:'#F7F7FB'}">
                <el-table-column property="protectLevel" label="防护等级"></el-table-column>
                <el-table-column label="试品长度(m)">
                  <template slot-scope="props">
                    <div class="defend"><el-form-item label-width="0px" :prop="'defendTableData.' + props.$index + '.productLength'" :rules="[{ required: true, message: '请输入试品长度', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.productLength" size="small" placeholder="请输入试品长度" clearable></el-input>
                    </el-form-item></div>
                  </template>
                </el-table-column>
                <el-table-column label="试品宽度(m)">
                  <template slot-scope="props">
                    <div class="defend"><el-form-item label-width="0px" :prop="'defendTableData.' + props.$index + '.productWidth'" :rules="[{ required: true, message: '请输入试品高度', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.productWidth" size="small" placeholder="请输入试品宽度" clearable></el-input>
                    </el-form-item></div>
                  </template>
                </el-table-column>
                <el-table-column label="试品高度(m)" property="productHeight">
                  <template slot-scope="props">
                    <div class="defend"><el-form-item label-width="0px" :prop="'defendTableData.' + props.$index + '.productHeight'" :rules="[{ required: true, message: '请输入试品高度', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.productHeight" size="small" placeholder="请输入试品高度" clearable></el-input>
                    </el-form-item></div>
                  </template>
                </el-table-column>
              </el-table>
            </el-form>
          </el-tab-pane>
        </el-tabs>
        <el-button type="primary" :loading="saveLoading" :disabled="saveButton" @click="saveValidate()" class="stroge">保存</el-button>
        <el-dialog title="提示" :visible.sync="remindVisible" width="30%" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
          <el-row style="font-size:15px;margin:30px 0 20px 40px">{{messageRemind}}</el-row>
          <span slot="footer" class="dialog-footer">
            <el-button v-if="remindFlag==403" @click="remindVisible=false;" style="width:140px;margin-right: 20px">取消</el-button>
            <el-button v-if="remindFlag==403" :loading="saveLoading" type="primary" style="width:140px" @click="saveValidate('continue')">确定</el-button>
            <el-button v-if="remindFlag==300" :loading="saveLoading" type="primary" style="width:140px" @click="saveValidate('sure')">确定</el-button>
          </span>
        </el-dialog>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    
    return {
      validateValue: (rule, value, callback) => {
      if (!/^\d+(\.\d{1,2})?$/.test(value)) {
        callback(new Error('输入值非法，请输入整数或至多两位小数'));
      }
      callback();
    },
      queryParams: '',
      saveLoading: false,
      liEquipParamsRules: {
        // chargTime: [
        //   { required: true, message: '该选项为必填项', trigger: 'blur'},
        //   { validator: validateValue, trigger: 'blur'}
        // ],
      },
      acWetEquipForm: {
        wetACTableData: [],
      },
      acWetEquipParams: {
        testKind: 2,
        collectInterval: null,
        horizCompont: null,
        rainElect: null,
        verticalCompont: null,
        waterTemp: null,
        withstandTime: null,
        highSpeed: null,
        lowSpeed: null,
      },
      kaData: [],
      remindFlag: null,
      remindVisible: false,
      messageRemind: '', // 启动前计算的值超出范围提示
      showDefend: false, // 防护试验显示
      defendParams: {
        protectId: '',
        defendTableData: []
      },
      oldTestNumber: '', // 旧委试号
      instrumentList: [],
      saveButton: false,
      publicTableData: [],
      publicParams: {
        gasKind: '',
        gjbName: '',
        ifInflate: '',
        kaM: null,
        prodName: '',
        seaLevel: null,
        setPress: null,
        testKind: '',
        tpltName: '',
        testNumber: '', // 委试号
        temperature: '', // 温度
        humidity: '', // 湿度
        pressure: '' // 大气压
      },
      showliEquip: false,
      equipTableData: [],
      liEquipParams: {
        bufferCnt: null,
        chargeCnt: null,
        chargeTime: null,
        chargeVolt: null,
        ifDischarge: '',
        paramC: '',
        paramC1:'',
        paramRf: '',
        paramRt: ''
      },
      acEquipParams: {
        testKind: 1,
        collectInterval: null,
        withstandTime: null,
        highSpeed: null,
        lowSpeed: null,
      },
      showACEquip: false,
      showACWet: false,
      activeName: 'first',
      oldActiveName: 'first',
      dataLoading: false,
      acEquipForm: {
        acEquipTableData: [],
      },
      liEquipForm: {
        liEquipTableData: []
      },
      publicParamsRules: {
        testNumber: [
          { required: true, message: '请输入委试号', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init(){
      console.info('--------编辑参数初始接参--------')
      console.info(this.$route.query)
      this.queryParams = this.$route.query;
      this.getTestParams();
    },
    // 获取雷电设备参数
    async getACInstParams() {
      let params;
      for (let i=0; i<this.instrumentList.length; i++) {
        if (/雷电冲击耐受电压试验设备/.exec(this.instrumentList[i].kind_name)!== null && /雷电冲击耐受电压试验设备/.exec(this.instrumentList[i].kind_name)[0] === '雷电冲击耐受电压试验设备') {
          params = {
            instrId: this.instrumentList[i].instr_id
          }
          const ret = await this.$http.get("/testPlan/getInstrumentParams",{params,});
          for(let j=0; j<ret.result.length; j++) {
            if(/^C\(μF\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramC = ret.result[i].param_val;
            }
            if(/^C1\(pF\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramC1 = ret.result[i].param_val;
            }
            if(/^Rf\(Ω\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramRf = ret.result[i].param_val;
            }
            if(/^Rt\(Ω\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramRt = ret.result[i].param_val;
            }
          }
          break
        }
      }
    },
    // 获取测试参数
    async getTestParams(){
      this.dataLoading = true;
      let reciveParams;
      let voltParams;
      if (this.$route.query.edit === undefined) { // 根据edit标记选择从api还是传参获取数据
        const reviceInstance = this.$route.query.instanceId;
        const params = {
          planId: reviceInstance === ''? this.$route.query.planId : 0,
          instanceId: reviceInstance === ''? 0 : reviceInstance
        }
        const ret = await this.$http.get("/runningTest/getConfimParams",{params,});
        console.info('------------编辑调接口获取参数---------------')
        reciveParams = ret.result;
      } else {
        console.info('------------编辑页面传参---------------')
        reciveParams = this.$route.query.testParams;
      }
      console.info(reciveParams);
      this.publicParams = reciveParams.confimParams;
      this.instrumentList = reciveParams.instrument;
      this.oldTestNumber = this.$route.query.testNumber;
      this.$set(this.publicParams,"testNumber",this.$route.query.testNumber);
      this.publicParams.temperature = this.$route.query.temperature;
      this.publicParams.humidity = this.$route.query.humidity;
      this.publicParams.pressure = this.$route.query.pressure;
      voltParams = reciveParams.voltParamsDemo;
      for (let i=0; i<voltParams.length; i++){ // 根据试验类型进行电压参数分类
        if (voltParams[i].test_kind === 1) {
          this.acEquipForm.acEquipTableData.push(JSON.parse(JSON.stringify(voltParams[i])));
        } else if (voltParams[i].test_kind === 3) {
          this.liEquipForm.liEquipTableData.push(JSON.parse(JSON.stringify(voltParams[i])));
        } else if (voltParams[i].test_kind === 2) {
          this.acWetEquipForm.wetACTableData.push(JSON.parse(JSON.stringify(voltParams[i])));
        }
      }
      const testKind = this.publicParams.testKind.split(',');
      for (let i=0; i<testKind.length; i++){ // 根据已逗号分隔的试验类型进行tab页显示
        if (testKind[i] === '1') {
          this.showACEquip = true;
          this.activeName = 'second';
        } else if (testKind[i] === '3') {
          this.showliEquip = true;
          this.activeName = 'first';
        } else if (testKind[i] === '9') {
          this.showDefend = true;
          this.activeName = 'third';
        } else if (testKind[i] === '2') {
          this.showACWet = true;
          this.activeName = 'fourth';
        }
      }
      // 将试验类型数字转换为相对应的汉字进行显示
      this.publicParams.testKind = this.publicParams.testKind.replace(new RegExp('1','g'),'工频耐受电压试验');
      this.publicParams.testKind = this.publicParams.testKind.replace(new RegExp('2','g'),'工频耐受电压试验\(湿\)');
      this.publicParams.testKind = this.publicParams.testKind.replace(new RegExp('3','g'),'雷电冲击耐受电压试验');
      this.publicParams.testKind = this.publicParams.testKind.replace(new RegExp('9','g'),'气候防护试验');
      this.publicParams.testKind = this.publicParams.testKind.replace(new RegExp('5','g'),'辅助和控制回路的绝缘试验');
      if (reciveParams.LIParams !== undefined) {
        this.liEquipParams = reciveParams.LIParams;
        await this.getACInstParams();
      }
      for (let i=0; i<reciveParams.ACParams.length; i++) {
        if (reciveParams.ACParams[i].testKind === 1) {
          this.acEquipParams = reciveParams.ACParams[i];
        } else {
          this.acWetEquipParams = reciveParams.ACParams[i];
        }
      }
      if (reciveParams.protectInfo !== undefined && reciveParams.protectInfo.protectData.length !== 0) {
        this.defendParams.protectId = reciveParams.protectInfo.protectStr.protectLevel;
        this.allDefendData = reciveParams.protectInfo.protectData;
        for (let i=0; i<this.allDefendData.length; i++){
          if (this.allDefendData[i].protectId === 8 || this.allDefendData[i].protectId === 10 || this.allDefendData[i].protectId === 11 || this.allDefendData[i].protectId === 12 || this.allDefendData[i].protectId === 13) {
            this.defendParams.defendTableData.push(this.allDefendData[i]);
          }
        }
      }
      this.dataLoading = false;
    },
    // 保存参数，如果是试验暂停进入此界面，点击保存调api并进行保存前计算kaData；未启动试验则将数据以传参的形式传递
    async saveTestParams(flag){
      this.saveLoading = true;
      let voltParams = [];
      let query = {
        edit: true,
        update: 0,
        duration: this.$route.query.duration,
        beginTime: this.$route.query.beginTime,
        schedule: this.$route.query.schedule,
        alarmCout: this.$route.query.alarmCout,
        editDisable: this.$route.query.editDisable,
        planId: this.$route.query.planId,
        planName: this.$route.query.planName,
        sign: this.$route.query.sign,
        buttonSign: this.$route.query.buttonSign,
        instanceId: this.$route.query.instanceId,
        testNumber: this.publicParams.testNumber,
        temperature: this.publicParams.temperature,
        humidity: this.publicParams.humidity,
        pressure: this.publicParams.pressure,
        oldTestNumber: this.oldTestNumber,
        testPartInfo: this.$route.query.testPartInfo,
        testPartList: this.$route.query.testPartList,
        instrumentData: this.$route.query.instrumentData,
        tpltId: this.$route.query.tpltId,
        allTestPartList: this.$route.query.allTestPartList,
        testParams:{
          instrument: this.instrumentList,
          ACParams: []
        }
      }
      voltParams = voltParams.concat(this.acEquipForm.acEquipTableData,this.liEquipForm.liEquipTableData,this.acWetEquipForm.wetACTableData);
      let params = {
        info: {
          instance_id: this.$route.query.instanceId,
          test_number: this.$route.query.testNumber,
          voltParamsDemo: JSON.stringify(voltParams)
        }
      }
      if (this.$route.query.buttonSign !== 'true') {
        this.$message.success('正在保存数据,请稍后!');
        const detParams = {
          voltParamsDemo: JSON.stringify(voltParams),
          atmosphere: {
            instance_id: this.$route.query.instanceId,
            RH: Number(this.publicParams.humidity),
            ATM: Number(this.publicParams.pressure),
            T: Number(this.publicParams.temperature)
          },
          publicParam: {
            seaLevel: this.publicParams.seaLevel,
            kaM: this.publicParams.kaM
          },
          flag: flag === undefined? 0:1
        }
        let ret;
        console.info('---------flag-----------')
        console.info(flag)
        query.sign = 'runningTest';
        query.runningStatus = 0;
        query.update = 1;
        if (flag === undefined || flag === 'continue') {
          console.info('-------编辑detParams----------');
          console.info(detParams)
          ret = await this.$http.get("/runningTest/determineParameters",{params:detParams,});
          this.remindFlag = ret.code;
          if (ret.code === 200) {
            this.kaData = ret.kaData;
            for (let i=0; i<this.kaData.length; i++) {
              if (this.kaData[i]==null) {
                this.$message.error('参数存在问题，无法计算出ka，请检查参数！');
                this.saveLoading = false;
                return
              }
            }
            params.kaData = ret.kaData;
            params.atmosphere = detParams.atmosphere;
            console.info('-------保存数据下发参数----------');
            console.info(params);
            ret = await this.$http.put("/runningTest/updateRunningParams",params);
          } else if (ret.code == 403 || ret.code == 300) {
            this.messageRemind = ret.message;
            this.remindVisible = true;
            this.saveLoading = false;
            return;
          }
        }
        if (flag === 'sure') {
          params.kaData = this.kaData;
          ret = await this.$http.put("/runningTest/updateRunningParams",params);
        }
        if (ret.code === 200){
          this.$message.success('保存成功');
          this.$router.push({
            path:'/TestPlanRunning',
            query: query
          });
        }
      } else {
        if (this.showACEquip === true) {
          query.testParams.ACParams.push(this.acEquipParams);
        }
        if (this.showliEquip === true) {
          query.testParams.LIParams = this.liEquipParams
        }
        if (this.showACWet === true) {
          query.testParams.ACParams.push(this.acWetEquipParams);
        }
        if (this.showDefend === true) {
          query.testParams.protectInfo = {
            protectData: this.allDefendData,
            protectStr: {
              protectLevel: this.defendParams.protectId
            }
          }
        }
        this.publicParams.testKind = this.publicParams.testKind.replace(/工频耐受电压试验\(湿\)/g.exec(this.publicParams.testKind),'2');
        this.publicParams.testKind = this.publicParams.testKind.replace(/工频耐受电压试验/g.exec(this.publicParams.testKind),'1');
        this.publicParams.testKind = this.publicParams.testKind.replace(/雷电冲击耐受电压试验/g.exec(this.publicParams.testKind),'3');
        this.publicParams.testKind = this.publicParams.testKind.replace(/辅助和控制回路的绝缘试验/g.exec(this.publicParams.testKind),'5');
        this.publicParams.testKind = this.publicParams.testKind.replace(/气候防护试验/g.exec(this.publicParams.testKind),'9');
        query.testParams.confimParams = this.publicParams;
        query.testParams.voltParamsDemo = voltParams;
        this.$message.success('保存成功');
        this.$router.push({
          path:'/TestPlanRunning',
          query: query
        });
      }
    },
    // 保存前的校验
    saveValidate(flag){
      let saveFlag = 0;
      this.$refs['publicParams'].validate((valid) => {
        if (valid) {
          saveFlag = 1;
        }else{
          saveFlag = 0;
        }
      });
      if (saveFlag === 0) {
        this.$message.error('您未填写委试号!');
        return
      }
      if (this.showliEquip === true) {
        this.$refs['liEquipForm'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中雷电部位电压参数!');
          return
        }
      }
      if (this.showACEquip === true) {
        this.$refs['acEquipForm'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中工频耐受电压试验部位电压参数!');
          return
        }
      }
      if (this.showACWet === true) {
        this.$refs['acWetEquipForm'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中工频耐受电压试验(湿)部位电压参数!');
          return
        }
      }
      if (this.showDefend === true) {
        this.$refs['defendParams'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整气候防护参数!');
          return
        }
      }
      this.saveTestParams(flag);
    }
  },
  mounted() {
    this.init();
	}
}
</script>
<style lang="scss" scoped>
@import "./TestParamsDisplay.scss";
</style>